package com.deer.wms.base.system.web.task;

import com.deer.wms.base.system.model.task.TaskInfoCriteria;
import com.deer.wms.base.system.model.task.TaskInfoDto;
import com.deer.wms.base.system.service.task.TaskInfoHistoryService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
/***
 *入库历史任务
 * @param
 * @author 李帅辰
 * @date 2020/10/9 9:05 
 * @return 
 */
@Controller
@RequestMapping("/in/billInTaskInfoHistory")
public class BillInTaskInfoHistoryController extends BaseController {
    @Autowired
    private TaskInfoHistoryService taskInfoHistoryService;

    private String prefix = "task";

    @RequiresPermissions("in:billInTaskInfoHistory:view")
    @GetMapping("/page")
    public String taskInfo() {
        return prefix + "/billInTaskInfoHistory";
    }

    /**
     * 查询入库历史任务列表
     */
    @PostMapping("/billInFindList")
    @ResponseBody
    public TableDataInfo findList(TaskInfoCriteria taskInfoCriteria) {
        startPage();
        List<TaskInfoDto> list = taskInfoHistoryService.billInFindList(taskInfoCriteria);
        return getDataTable(list);
    }
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskInfoCriteria taskInfoCriteria) {

        List<TaskInfoDto> list = taskInfoHistoryService.billInFindList(taskInfoCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(list, "入库历史作业");
    }
    /**
     * 导出列表
     */
    //@RequiresPermissions("in:billInMaster:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam String ids) {
        List<TaskInfoDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            TaskInfoCriteria b=new TaskInfoCriteria ();
            b.setBillId(Integer.parseInt(s));
            List<TaskInfoDto> list = taskInfoHistoryService.billInFindList(b);
            for (TaskInfoDto bs:list
            ) {
                byIds.add(bs);
            }

        }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(byIds, "入库历史作业");
    }
}
